package com.yoga.utils;

import javax.servlet.http.HttpSession;

public class TimeUtils {
    public static final long INTERVAL = 60 * 1000; // 60秒内不能重复发送验证码

    public static boolean canSendCaptcha(HttpSession session, String phone) {
        Long lastSendTime = (Long) session.getAttribute(phone + "_lastSendTime");
        if (lastSendTime == null) {
            return true;
        }
        long currentTime = System.currentTimeMillis();
        return (currentTime - lastSendTime) > INTERVAL;
    }

    public static void updateLastSendTime(HttpSession session, String phone) {
        session.setAttribute(phone + "_lastSendTime", System.currentTimeMillis());
    }
}
